package com.lry.rpc.config;

import io.netty.channel.ServerChannel;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.Data;

@Data
public class NettyServerConfig extends NettyBaseConfig{

    public static final Class<? extends ServerChannel> SERVER_CHANNEL_CLAZZ = NioServerSocketChannel.class;

    private String applicationName = "RpcServer";
    private int bossThreads = 1;
    private int workerThreads = 100;
    private  int port = 8091;
    private int soBackLogSize = 1024;
    private int serverSocketSendBufSize = 153600;
    private int serverSocketResvBufSize = 153600;
    private int writeBufferHighWaterMark = 67108864;
    private int writeBufferLowWaterMark = 1048576;
    private static final int RPC_REQUEST_TIMEOUT = 30 * 1000;


    public void setPort(Integer port){
        //检查端口范围
        if(null==port){
            return;
        }
        this.port = port;
    }
    public static boolean enableEpoll(){
        return Epoll.isAvailable();
    }

    public static int getRpcRequestTimeout() {
        return RPC_REQUEST_TIMEOUT;
    }

    public long getServerShutdownWaitTime() {
        return 1;
    }

    public int getBossThreadSize() {
        return bossThreads;
    }

    public int getServerWorkerThreads() {
        return workerThreads;
    }

    public int getChannelMaxReadIdleSeconds() {
        return MAX_READ_IDLE_SECONDS;
    }
}
